"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
"""
# 导入 flask 和 flask_sqlalchemy
import logging

from flask import Flask
from flask_cors import CORS
from flask_restx import Api
from flask_jwt_extended import JWTManager
from flask_sqlalchemy import SQLAlchemy

# 实例化app 对象
app = Flask(__name__)

#自动在报文头部加入相应内容，解决跨域问题
CORS(app, resources=r'/*')

#注册restx
api = Api(app)

#注册jwt
app.config['JWT_SECRET_KEY'] = 'jose'  # token密钥
app.config['JWT_BLACKLIST_ENABLED'] = True  # 黑名单管理
app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['access', 'refresh']  # 允许将access and refresh tokens加入黑名单
jwt = JWTManager(app)

#注册sqlalchemy
username = "root"
pwd = "123456"
ip = "42.192.73.147"
port = "3306"
database = "test_server"
app.config['SQLALCHEMY_DATABASE_URI'] = f"mysql+pymysql://{username}:{pwd}@{ip}:{port}/{database}?charset=utf8"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.logger.setLevel(logging.DEBUG)
# SQLAlchemy 绑定 app
db = SQLAlchemy(app)

# 绑定 方法与路由 的关联
def router():
    from controller.test_case_controller import case_ns
    from controller.user_controller import user_ns
    api.add_namespace(case_ns, '/testcase')
    api.add_namespace(user_ns, '/user')

if __name__ == '__main__':
    router()
    app.run(host="0.0.0.0")
    # app.run(debug=True)